package cn.shiva.springaop.config;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author shiva   2022-09-14 22:20
 */
@Slf4j
@Aspect
@Component
public class ServiceAspect {

    @Pointcut(value = "execution(* cn.shiva.springaop.service.NoticeService.*(..))")
    public void pointCut() {
    }

    @Before("pointCut()")
    public void before() {
        log.info("1.前置通知，方法执行之前。");
    }

    @AfterReturning("pointCut()")
    public void afterReturning() {
        log.info("2.后置通知，方法返回参数之后。");
    }

    @After("pointCut()")
    public void after() {
        log.info("3.最终通知，全部执行结束之后。");
    }

    @AfterThrowing("pointCut()")
    public void afterThrowing() {
        log.info("9.异常通知，抛出异常之后。");
    }

    @Around("pointCut()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        log.info("环绕通知执行之前");
        proceedingJoinPoint.proceed();//被增强的方法执行
        log.info("环绕通知执行之后");
        return "环绕通知返回值";
    }
}
